package com.mhc.suzuki.service.scheduled;

import com.mhc.suzuki.constant.DirConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;


/**
 * 定时删除服务器临时文件
 *
 * @author kanon
 * @create 2017-09-08 11:52
 **/
@Slf4j
@Component
public class ClearFileTask {

    @Autowired
    private DirConfig dirConfig;

    @Scheduled(cron = "0 59 23 * * *")
    public void reportCurrentTime() {
        try {
            log.info("ClearFileTask运行开始");
            File resourcesFile = new File(dirConfig.getTmpDir());     //源文件
            FileUtils.deleteDirectory(resourcesFile);

            File resourcesZipFile = new File(dirConfig.getZipTmpDir());     //源文件
            FileUtils.deleteDirectory(resourcesZipFile);
            log.info("ClearFileTask运行结束");
        } catch (IOException e) {
            log.error("IOException", e);
        }
    }


}
